/*
VARIABLES
See online_survey_codebook.docx

Note: This file allows reproducing
 Figures: 2, 3, B.1-B.4 
 Tables: B.1-B.15
*/


*Load online_survey_data.dta


set scheme white_tableau

*---DATA PREPARATION---*

*Alienation index
recode v_41 v_42 v_44 v_46 (1=5) (2=4) (4=2) (5=1) // adjust scale, so high values=high alienation
egen alienation=rowmean(v_40-v_47) 
lab var alienation "Alienation index"

*Vote propensity indices
egen leftvote=rowmean(v_49-v_51)
lab var leftvote "Left index"

*Education: Merge / drop small categories
clonevar educ=v_30
recode educ (1=2) (6=.)
lab var educ "School education 2"
label define v_30 2 "Low" 3 "Medium" 4 "Med-high" 5 "High", modify


*Collapse PID in left, right, other, none.
ge pid=v_83
recode pid (2 3 5=1) (1 4 6=2) (7=3) (8=4)
lab var pid "PID collapsed"
lab define pidlb 1"Left" 2"Right" 3"Other" 4"No"
lab val pid pidlb

*Recode gender: "diverse" has to be dropped, n=1
recode v_27 (3=.) 

*Recode residence: merge two rural categories
recode v_121 (5=4)
label define v_121 1"City" 2"Conurbation" 3"Sm./med. town" 4"Rural", modify


*---FIGURE 2---*
*Flag cases with use of *
gen star = (strpos(response, "*")!=0)
lab var star "Gender sign * used"
*Flag cases with use of *, /, or :
gen punctuation = strpos(response, "*") | strpos(response, "/") | strpos(response, ":")
lab var punctuation "Gender signs */: used"

*Flag cases with reference to 'gender' or 'sprach'
gen gender = strpos(response, "gender") | strpos(response, "Gender") | strpos(response, "sprach") | strpos(response, "Sprach") 
gen gender2 = strpos(response, "gender") | strpos(response, "Gender") 
lab var gender "Reference to 'gender' or 'language'"


*Figure 2
global mopts "recast(scatter) horizontal plot1opts(lcolor(black) mcolor(black)) ciopt(color(black)) yscale(reverse) xtitle("") ytitle("") graphregion(margin(vsmall)) nodraw"

*Panel A
quietly logit star i.treatment
quietly margins, over(treatment) 
marginsplot, $mopts title({bf:(A) Asterisk}, margin(tiny) size(small) xoffset(40)) name(star, replace)

*Panel B
quietly logit gender i.treatment
quietly margins, over(treatment) 
marginsplot, $mopts  title({bf:(B) Gender/language reference}, margin(tiny) size(small) xoffset(40)) name(gender, replace)

graph combine star gender, ycommon common ysize(1) iscale(*5) graphregion(margin(zero))


*---FIGURE 3---*
global est "(p50, color(cranberry) ciop(color(cranberry)) ms(d)) (p51, color(green) ciop(color(green)) ms(o)) (p49, color(purple%70) ciop(color(purple%70)) ms(s)) (p52, color(black) ciop(color(black)) ms(d) mfcolor(white)) (p53, color(gold) ciop(color(gold)) ms(o) mfcolor(white)) (p48, color(midblue) ciop(color(midblue)) ms(s) mfcolor(white)) (p54, color(gs13) ciop(color(gs13)) ms(t))"
global opts "drop(_cons) yline(0, lw(med) lp(solid) lc(black)) plotlabels("SPD" "Greens" "Left" "CDU" "FDP" "AfD" "Abstain") plotregion(margin(zero)) vertical "

forv i = 48/54 {
reg v_`i' i.treat
estimates store p`i'
}
coefplot $est , $opts title({bf:Full sample}, size(small) ring(0) pos(12) yoffset(1)) name(all, replace)

forv i = 48/54 {
reg v_`i' i.treat if v_27==1
estimates store p`i'
}
coefplot $est , $opts title({bf:Men},size(small) ring(0) pos(12) yoffset(1)) name(men, replace) 

forv i = 48/54 {
reg v_`i' i.treat if v_30<=3
estimates store p`i'
}
coefplot $est , $opts title({bf:Below university},size(small) ring(0) pos(12) yoffset(1)) name(low, replace) 

forv i = 48/54 {
reg v_`i' i.treat if v_27==1 & v_30<=3
estimates store p`i'
}
coefplot $est , $opts  title({bf:Men below university},size(small) ring(0) pos(12) yoffset(1)) name(menlow, replace) 


grc1leg2 all men low menlow, position(6) lrows(1) lyoffset(-1.2) legscale(3.5) ycommon xcommon graphregion(margin(tiny)) ysize(3) iscale(*1.5)

*---FIGURE B.1---*
  forval k = 40/47 {
  quietly reg v_`k' i.treat 
  estimates store item`k'
  }
quietly reg alienation i.treat
estimates store itemalien

coefplot (itemalien, ms(T)) (item40, ms(O))  (item41, ms(D)) (item42, ms(S)) (item43, ms(X) msize(large)) (item44, ms(T) mfcolor(white)) (item45, ms(O) mfcolor(white)) (item46, ms(S) mfcolor(white)) (item47, ms(D) mfcolor(white)), ///
         drop(_cons) xline(0) msize(medsmall) ///
		 plotlabels("Alienation index" "MPs different world" "MPs similar to me (reverse)" "Represented well (reverse)" "Care about my interests" "Appreciated by society (reverse)" ///
         "Less recognition" "Parties trustworthy (reverse)" "Parties only want votes")

		 

*---FIGURE B.2---*
global append_opts "nodraw recast(scatter) yline(0,lp(solid) lc(black)) ytitle("") xtitle("") plot1opts(msymbol(S)) plot2opts(msymbol(Oh)) plot3opts(msymbol(X)) graphregion(margin(medsmall)) plotregion(margin(medsmall))"

*Eduction
quietly: reg alien treat##educ
quietly: margins, dydx(treat) over(educ)
mplotoffset, $append_opts ///
             offset(0.1) xlabel(2"Low" 3"Medium" 4"Med-high" 5"High") ///
			 title("School education", margin(medsmall) yoffset(-2)) ///
			 name(aleduc, replace) plot( , label("Passive GNL" "Active GNL" "Technical")) legend(region(color(gs15)))
			 
*Income
quietly: reg alien treat##c.v_120
quietly: margins, dydx(treat) over(v_120)
mplotoffset, $append_opts ///
             offset(0.2) xlabel(1 "<500" 2 " " 3 "1000" 4 " " 5 "1500" 6 " " 7 "2500" 8 " " 9 "4000" 10 " " 11 "7500" 12 " " 13 ">10000") ///
			 title("Net income (EUR)", margin(medsmall) yoffset(-2)) ///
			 name(alinc, replace)

*Subj status
quietly: reg alien treat##c.v_81
quietly: margins, dydx(treat) over(v_81)
mplotoffset, $append_opts ///
             offset(0.2) xlabel(1 "Bottom" 2 "" 3 "" 4 "" 5 "" 6 "" 7 "" 8 "" 9 "" 10 "Top") ///
			 title("Subjective status", margin(medsmall) yoffset(-2)) ///
			 name(alst, replace)
			 
*Ideology
quietly: reg alien treat##c.v_34
quietly: margins, dydx(treat) over(v_34)
mplotoffset, $append_opts ///
             offset(0.2) xlabel(1 "Left" 2 "1" 3 "2" 4 "3" 5 "4" 6 "5" 7 "6" 8 "7" 9 "8" 10 "9" 11 "Right") ///
			 title("Left-right ideology", margin(medsmall) yoffset(-2)) ///
			 name(allr, replace)

*PID
quietly: reg alien treat##pid
quietly: margins, dydx(treat) over(pid)
mplotoffset, $append_opts ///
             offset(0.1) xlabel(1"Left" 2"Right" 3"Other" 4"No") ///
			 title("Party identification", margin(medsmall) yoffset(-2)) ///
			 name(alpid, replace)

*Gender
quietly: reg alien treat##v_27
quietly: margins,dydx(treat) over(v_27)
mplotoffset, xdimension(v_27) $append_opts ///
             offset(0.03) xlabel(1"Male" 2"Female") ///
			 title("Gender", margin(medsmall) yoffset(-2)) ///
			 name(algend, replace) 

*Rural-urban
quietly: reg alien treat##v_121
quietly: margins, dydx(treat) over(v_121)
mplotoffset, $append_opts ///
             offset(0.1) xlabel(1"City" 2"Conurbation" 3"Sm./med. town" 4"Rural") ///
			 title("Rural-urban", margin(medsmall) yoffset(-2)) ///
			 name(alres, replace)

*Age
quietly: reg alien treat##c.v_29
quietly: margins,dydx(treat) over(v_29)
mplotoffset, $append_opts ///
             offset(0.5) xlabel(20(10)60) ///
			 title("Age", margin(medsmall) yoffset(-2)) ///
			 name(alage, replace)

grc1leg2 aleduc alinc alst alage alres algend allr alpid , ///
         legendfrom(aleduc) ring(0) position(5) holes(9) lcols(1) legscale(3) lyoffset(4) lxoffset(-4) ///
         graphregion(margin(tiny)) ltitle("Experimental group")					
			 

			 
*---FIGURE B.3---*

*Eduction
quietly: reg leftvote treat##educ
quietly: margins, dydx(treat) over(educ)
mplotoffset, $append_opts ///
             offset(0.1) xlabel(2"Low" 3"Medium" 4"Med-high" 5"High") ///
			 title("School education", margin(medsmall) yoffset(-2)) ///
			 name(lveduc, replace) plot( , label("Passive GNL" "Active GNL" "Technical")) legend(region(color(gs15)))
			 
*Income
quietly: reg leftvote treat##c.v_120
quietly: margins, dydx(treat) over(v_120)
mplotoffset, $append_opts ///
             offset(0.2) xlabel(1 "<500" 2 " " 3 "1000" 4 " " 5 "1500" 6 " " 7 "2500" 8 " " 9 "4000" 10 " " 11 "7500" 12 " " 13 ">10000") ///
			 title("Net income (EUR)", margin(medsmall) yoffset(-2)) ///
			 name(lvinc, replace)

*Subj status
quietly: reg leftv treat##c.v_81
quietly: margins, dydx(treat) over(v_81)
mplotoffset, $append_opts ///
             offset(0.2) xlabel(1 "Bottom" 2 "" 3 "" 4 "" 5 "" 6 "" 7 "" 8 "" 9 "" 10 "Top") ///
			 title("Subjective status", margin(medsmall) yoffset(-2)) ///
			 name(lvst, replace)
			 
*Ideology
quietly: reg leftvote treat##c.v_34
quietly: margins, dydx(treat) over(v_34)
mplotoffset, $append_opts ///
             offset(0.2) xlabel(1 "Left" 2 "1" 3 "2" 4 "3" 5 "4" 6 "5" 7 "6" 8 "7" 9 "8" 10 "9" 11 "Right") ///
			 title("Left-right ideology", margin(medsmall) yoffset(-2)) ///
			 name(lvlr, replace)

*PID
quietly: reg leftvote treat##pid
quietly: margins, dydx(treat) over(pid)
mplotoffset, $append_opts ///
             offset(0.1) xlabel(1"Left" 2"Right" 3"Other" 4"No") ///
			 title("Party identification", margin(medsmall) yoffset(-2)) ///
			 name(lvpid, replace)

*Gender
quietly: reg leftvote treat##v_27
quietly: margins,dydx(treat) over(v_27)
mplotoffset, xdimension(v_27) $append_opts ///
             offset(0.03) xlabel(1"Male" 2"Female") ///
			 title("Gender", margin(medsmall) yoffset(-2)) ///
			 name(lvgend, replace) 

*Rural-urban 
quietly: reg leftvote treat##v_121
quietly: margins, dydx(treat) over(v_121)
mplotoffset, $append_opts ///
             offset(0.1) xlabel(1"City" 2"Conurbation" 3"Sm./med. town" 4"Rural") ///
			 title("Rural-urban", margin(medsmall) yoffset(-2)) ///
			 name(lvres, replace)

*Age
quietly: reg leftvote treat##c.v_29
quietly: margins,dydx(treat) over(v_29)
mplotoffset, $append_opts ///
             offset(0.5) xlabel(20(10)60) ///
			 title("Age", margin(medsmall) yoffset(-2)) ///
			 name(lvage, replace)
		 
grc1leg2 lveduc lvinc lvst lvage lvres lvgend lvlr lvpid , ///
         legendfrom(lveduc) ring(0) position(5) holes(9) lcols(1) legscale(3) lyoffset(4) lxoffset(-4) ///
         graphregion(margin(tiny)) ltitle("Experimental group")


*---FIGURE B.4---*

*Eduction
quietly: reg v_51 treat##educ
quietly: margins, dydx(treat) over(educ)
mplotoffset, $append_opts ///
             offset(0.1) xlabel(2"Low" 3"Medium" 4"Med-high" 5"High") ///
			 title("School education", margin(medsmall) yoffset(-2)) ///
			 name(gveduc, replace) plot( , label("Passive GNL" "Active GNL" "Technical")) legend(region(color(gs15)))
			 
*Income
quietly: reg v_51 treat##c.v_120
quietly: margins, dydx(treat) over(v_120)
mplotoffset, $append_opts ///
             offset(0.2) xlabel(1 "<500" 2 " " 3 "1000" 4 " " 5 "1500" 6 " " 7 "2500" 8 " " 9 "4000" 10 " " 11 "7500" 12 " " 13 ">10000") ///
			 title("Net income (EUR)", margin(medsmall) yoffset(-2)) ///
			 name(gvinc, replace)
*Subj status
quietly: reg v_51 treat##c.v_81
quietly: margins, dydx(treat) over(v_81)
mplotoffset, $append_opts ///
             offset(0.2) xlabel(1 "Bottom" 2 "" 3 "" 4 "" 5 "" 6 "" 7 "" 8 "" 9 "" 10 "Top") ///
			 title("Subjective status", margin(medsmall) yoffset(-2)) ///
			 name(gvst, replace)

			 
*Ideology
quietly: reg v_51 treat##c.v_34
quietly: margins, dydx(treat) over(v_34)
mplotoffset, $append_opts ///
             offset(0.2) xlabel(1 "Left" 2 "1" 3 "2" 4 "3" 5 "4" 6 "5" 7 "6" 8 "7" 9 "8" 10 "9" 11 "Right") ///
			 title("Left-right ideology", margin(medsmall) yoffset(-2)) ///
			 name(gvlr, replace)

*PID
quietly: reg v_51 treat##pid
quietly: margins, dydx(treat) over(pid)
mplotoffset, $append_opts ///
             offset(0.1) xlabel(1"Left" 2"Right" 3"other" 4"No") ///
			 title("Party identification", margin(medsmall) yoffset(-2)) ///
			 name(gvpid, replace)

*Gender  
quietly: reg v_51 treat##v_27
quietly: margins,dydx(treat) over(v_27)
mplotoffset, xdimension(v_27) $append_opts ///
             offset(0.03) xlabel(1"Male" 2"Female") ///
			 title("Gender", margin(medsmall) yoffset(-2)) ///
			 name(gvgend, replace) 

*Rural-urban 
quietly: reg v_51 treat##v_121
quietly: margins, dydx(treat) over(v_121)
mplotoffset, $append_opts ///
             offset(0.1) xlabel(1"City" 2"Conurbation" 3"Sm./med. town" 4"Rural") ///
			 title("Rural-urban", margin(medsmall) yoffset(-2)) ///
			 name(gvres, replace)

*Age 
quietly: reg v_51 treat##c.v_29
quietly: margins,dydx(treat) over(v_29)
mplotoffset, $append_opts ///
             offset(0.5) xlabel(20(10)60) ///
			 title("Age", margin(medsmall) yoffset(-2)) ///
			 name(gvage, replace)

grc1leg2 gveduc gvinc gvst gvage gvres gvgend gvlr gvpid , ///
         legendfrom(gveduc) ring(0) position(5) holes(9) lcols(1) legscale(3) lyoffset(4) lxoffset(-4) ///
         graphregion(margin(tiny)) ltitle("Experimental group") 


*---APPENDIX TABLES---*
label define treat 2 "Passive" 3 "Active", modify

*---TABLE B.1---*
tabstat v_40-v_47 alienation v_48-v_54 leftvo, c(stat) stat(mean sd min max n)

*---TABLE B.2---*
est clear
eststo: quietly: reg alienation i.treat
eststo: quietly: reg leftvote i.treat
eststo: quietly: reg v_51 i.treat
esttab est1 est2 est3, label b(3) se(3) nobaselevels interaction(" X ") noabbrev wrap wide ///
       refcat(2.treatment "Treatment (ref: Control)", nolabel) 

*---TABLE B.3---*	  
est clear
  forval k = 40/47 {
  eststo: reg v_`k' i.treat 
  estimates store item`k'
  }
esttab est1 est2 est3 est4 est5 est6 est7 est8, b(3) se(3) label nobaselevels interaction(" X ") noabbrev wrap ///
	   collabels(none) mlabel(none) nonotes refcat(2.treatment "Treatment (ref: Control)", nolabel)
	  
*---TABLE B.4---*
lab var v_120 "Income"
est clear
eststo: quietly: reg alien treat##c.v_120
eststo: quietly: reg leftvote treat##c.v_120 
eststo: quietly: reg v_51 treat##c.v_120
esttab est1 est2 est3, label b(3) se(3) nobaselevels interaction(" X ") noabbrev wrap wide ///
	   refcat(2.treatment "Treatment (ref: Control)" v_120 "" 2.treatment#c.v_120 "", nolabel)  

*---TABLE B.5---*
est clear
eststo: quietly: reg alien treat##educ // est1
eststo: quietly: reg leftvote treat##educ  // est2
eststo: quietly: reg v_51 treat##educ  // est3
esttab est1 est2 est3, label b(3) se(3) nobaselevels interaction(" X ") noabbrev wrap wide ///
	   refcat(2.treatment "Treatment (ref: Control)" 3.educ "\emph{Education (ref: Low)}" 2.treatment#3.educ "", nolabel) 

*---TABLE B.6---*	  
lab var v_81 "Status"
est clear
eststo: quietly: reg alien treat##c.v_81
eststo: quietly: reg leftvote treat##c.v_81
eststo: quietly: reg v_51 treat##c.v_81
esttab est1 est2 est3, label b(3) se(3) nobaselevels interaction(" X ") noabbrev wrap wide ///
	   refcat(2.treatment "Treatment (ref: Control)" v_81 "" 2.treatment#c.v_81 "", nolabel)  

*---TABLE B.7---*	  
lab var v_34 "Left-right"
est clear
eststo: quietly: reg alien treat##c.v_34
eststo: quietly: reg leftvote treat##c.v_34
eststo: quietly: reg v_51 treat##c.v_34
esttab est1 est2 est3, label b(3) se(3) nobaselevels interaction(" X ") noabbrev wrap wide ///
	   refcat(2.treatment "Treatment (ref: Control)" v_34 "" 2.treatment#c.v_34 "", nolabel)  

*---TABLE B.8---*	  
est clear
eststo: quietly: reg alien treat##pid
eststo: quietly: reg leftvote treat##pid
eststo: quietly: reg v_51 treat##pid
esttab est1 est2 est3, label b(3) se(3) nobaselevels interaction(" X ") noabbrev wrap wide ///
	   refcat(2.treatment "Treatment (ref: Control)" 2.pid "PID (ref: Left)" 2.treatment#2.pid "", nolabel)

*---TABLE B.9---*	  
est clear
eststo: quietly: reg alien treat##v_27
eststo: quietly: reg leftvote treat##v_27
eststo: quietly: reg v_51 treat##v_27
esttab est1 est2 est3, label b(3) se(3) nobaselevels interaction(" X ") noabbrev wrap wide ///
	   refcat(2.treatment "Treatment (ref: Control)" 2.v_27 "Gender (ref: Male)" 2.treatment#2.v_27 "", nolabel)

*---TABLE B.10---*	  
est clear
eststo: quietly: reg alien treat##c.v_29
eststo: quietly: reg leftvote treat##c.v_29
eststo: quietly: reg v_51 treat##c.v_29
esttab est1 est2 est3, label b(3) se(3) nobaselevels interaction(" X ") noabbrev wrap wide ///
	   refcat(2.treatment "Treatment (ref: Control)" v_29 "" 2.treatment#c.v_29 "", nolabel)  

*---TABLE B.11---*	  
est clear
eststo: quietly: reg alien treat##v_121
eststo: quietly: reg leftvote treat##v_121
eststo: quietly: reg v_51 treat##v_121
esttab est1 est2 est3, label b(3) se(3) nobaselevels interaction(" X ")  wrap wide ///
	   refcat(2.treatment "Treatment (ref: Control)" 2.v_121 "Residence (ref: City)" 2.treatment#2.v_121 "", nolabel)

*---TABLE B.12---*
est clear
forv i = 48/54 {
eststo: quietly: reg v_`i' i.treat
}
esttab est3 est4 est2 est5 est6 est1 est7, b(3) se(3) label nobaselevels interaction(" X ") noabbrev wrap  ///
	   collabels(none) mlabels("SPD" "Greens" "Left" "CDU" "FDP" "AfD" "Abstain") 

*---TABLE B.13---*
est clear	 
forv i = 48/54 {
eststo: quietly: reg v_`i' i.treat if v_27==1
}
esttab est3 est4 est2 est5 est6 est1 est7, b(3) se(3) label nobaselevels interaction(" X ") noabbrev wrap  ///
	   collabels(none) mlabels("SPD" "Greens" "Left" "CDU" "FDP" "AfD" "Abstain") 
	 
*---TABLE B.14---*
est clear
forv i = 48/54 {
eststo: quietly: reg v_`i' i.treat if v_30<=3
}
esttab est3 est4 est2 est5 est6 est1 est7, b(3) se(3) label nobaselevels interaction(" X ") noabbrev wrap  ///
	   collabels(none) mlabels("SPD" "Greens" "Left" "CDU" "FDP" "AfD" "Abstain") 

*---TABLE B.15---*
est clear
forv i = 48/54 {
eststo: quietly: reg v_`i' i.treat if v_27==1 & v_30<=3
estimates store p`i'
}
esttab est3 est4 est2 est5 est6 est1 est7, b(3) se(3) label nobaselevels interaction(" X ") noabbrev wrap  ///
	   collabels(none) mlabels("SPD" "Greens" "Left" "CDU" "FDP" "AfD" "Abstain") 



